//
//  TeaFlowCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2018/3/19.
//  Copyright © 2018年 kamangkeji. All rights reserved.
//

#import "TeaFlowCell.h"
#import "YYLabel.h"
#import "NSAttributedString+YYText.h"

@interface TeaFlowCell()
@property (weak, nonatomic) IBOutlet YYLabel *flowLab;


@end

@implementation TeaFlowCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(ActivityDetailModel *)model
{
    _model = model;
    if (!model) return;
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:model.flow];
    attri.yy_font = [UIFont systemFontOfSize:14];
    attri.yy_color = [UIColor blackColor];
    attri.yy_alignment = NSTextAlignmentJustified;
    attri.yy_lineSpacing = 6;
    attri.yy_kern = @(1);
    
    //计算文本尺寸
    CGSize maxSize = CGSizeMake(ScreenW-40, MAXFLOAT);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:attri];
    self.flowLab.textLayout = layout;
    self.flowLab.attributedText = attri;
    [self.flowLab sizeToFit];
}
- (CGFloat)calculateCellH:(ActivityDetailModel *)model
{
    if (!model) return 0;
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:model.flow];
    attri.yy_font = [UIFont systemFontOfSize:14];
    attri.yy_color = [UIColor blackColor];
    attri.yy_alignment = NSTextAlignmentJustified;
    attri.yy_lineSpacing = 6;
    attri.yy_kern = @(1);
    
    CGSize maxSize = CGSizeMake(ScreenW-40, MAXFLOAT);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:maxSize text:attri];
    self.flowLab.textLayout = layout;
    self.flowLab.attributedText = attri;
    return layout.textBoundingSize.height+30;
}

@end
